package com.liu.controller;

import com.liu.springmvc.annotation.RequestMapping;
import com.liu.springmvc.annotation.RequestParam;
import com.liu.springmvc.view.ModelAndView;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.Map;

/**
 * @author LIU
 * @version 1.0
 * @description TODO
 * @date 2024/1/23 15:08
 */
@Controller
public class HelloController {

    @RequestMapping("/hello")
    public String hello(@RequestParam("name") String name){
        return "hello control";
    }


    @RequestMapping("/hello2")
    public String hello2(@RequestParam("name") String name){
        return "hello 收到消息了";
    }

    /**
     * 视图返回类
     * http://localhost:8081/first.html?teacher=测试
     * @param teacher
     * @return
     */
    @RequestMapping("/first.html")
    public ModelAndView first(@RequestParam("teacher") String teacher){
        Map<String,Object> model = new HashMap<String,Object>();
        model.put("teacher", teacher);
        model.put("data", "测试数据");
        model.put("token", "123456");
        return new ModelAndView("first.html",model);
    }
    /**
     * 视图返回类 404请求
     * @return
     */
    @RequestMapping("/404")
    public ModelAndView query(){
        Map<String,Object> model = new HashMap<String,Object>();
        return new ModelAndView("404",model);
    }
}
